package com.winsdom.controller.CustomerManagementController;

import com.winsdom.anno.Authentication;
import com.winsdom.annotation.OperationLog;
import com.winsdom.result.Result;
import com.winsdom.service.ICustomerNotificationConfigService;
import com.winsdom.vo.CustomerNotificationConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.winsdom.enums.AuthenticationType.CUSTOMER_MANAGEMENT;

/**
 * 客户通知配置控制器
 * 用于管理客户的通知配置信息，包括查询和更新客户的通知设置
 * 支持配置通知类型、通知间隔、最大通知次数等参数
 */
@Slf4j
@RestController
@RequestMapping("/customer-notification")
@Api(tags = "客户管理接口", description = "客户通知配置管理接口")
@Authentication(value=CUSTOMER_MANAGEMENT)
public class NoticeConfigurationController {
    @Autowired
    private ICustomerNotificationConfigService customerNotificationConfigService;

    @GetMapping("/list")
    @ApiOperation(value = "查询通知配置", notes = "根据客户ID查询其通知配置信息列表")
    @OperationLog(description = "查询通知配置")
    public Result<List<CustomerNotificationConfigVO>> getCustomerNotificationConfig(@RequestParam Long customerId) {
        List<CustomerNotificationConfigVO> configs = customerNotificationConfigService.getConfigByCustomerId(customerId);
        return Result.success(configs);
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新通知配置", notes = "更新指定客户的通知配置信息，包括通知类型、间隔时间等参数")
    @OperationLog(description = "更新通知配置")
    public Result<Void> updateCustomerNotificationConfig(@RequestBody CustomerNotificationConfigVO configVO) {
        log.info("更新客户通知配置，请求数据：{}", configVO);
        try {
            customerNotificationConfigService.updateConfig(configVO);
            return Result.success();
        } catch (Exception e) {
            log.error("更新客户通知配置失败", e);
            return Result.error(500, e.getMessage());
        }
    }
}
